var param = new Object({
	init:function(){
		this.timeSize = ''
		this.queryDate = ''
		this.city_code = ''
	},
	setParam:function(){
		this.init()
		this.timeSize = $('input:radio[name="timeSize"]:checked').val();
		this.queryDate = $('#queryDate').val()
		this.city_code = $('#area').val()
	}
});
var areaUserCharts
var areaFlowCharts
var cigiflow
var bussinessGroupCharts
var appCharts
var sgwCharts
var terminalCharts
var datatable
var MapData;
var isFirst=0;//判断是否初次加载还是点击按钮查询
var isReposition=true;//是否重新定位
$(function() {
	showArearList("area");
	$('#cell_flow tbody').on('click', 'tr', function() {
		if ($(this).hasClass('selected')) {
			$(this).removeClass('selected');
		} else {
			datatable.$('tr.selected').removeClass('selected');
			$(this).addClass('selected');
		}
	});
	areaUserCharts = echarts.init(document.getElementById('areaUserCharts'));
	areaFlowCharts = echarts.init(document.getElementById('areaFlowCharts'));
	userFlowDistributeCharts = echarts.init(document.getElementById('userFlowDistributeCharts'));
	bussinessGroupCharts = echarts.init(document.getElementById('bussinessGroupCharts'));
	appCharts = echarts.init(document.getElementById('appCharts'));
	sgwCharts = echarts.init(document.getElementById('sgwCharts'));
	terminalCharts = echarts.init(document.getElementById('terminalCharts'));
	getList()
    $("input[name='type']").click(function(){
        isReposition=false;
        changeType();
    });

});
function getList() {
	param.setParam();
	console.log(param) 	
	
	if($('#area').val() != ''){
		$('#areaSelected').hide();
	}else{
		$('#areaSelected').show();
		getAreaUserCharts();
	    getAreaFlowCharts();
	}
    getUserFlowDistributeCharts();
    getTaiList();
    getBussinessGroupCharts();
    getAppCharts();
    getSgwCharts()
    getTerminalCharts()
    isReposition=true;
    getAreaHeatMap();
}

function getTaiList() {
	$("#cell_flow tbody tr").remove();
	if (datatable == undefined || datatable == "undefined" || datatable == null) {
	} else {
		datatable.destroy();
	}
	datatable = $('#cell_flow')
				.DataTable(
					{
						"aoColumnDefs" : [ {
							sDefaultContent : '',
							aTargets : [ '_all' ]
						} ],
						"bPaginate" : true, // 翻页功能
						"iDisplayLength" : 50,
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"ordering": true, //排序功能
						"bSort" : true, // 排序功能
						"bInfo" : true,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						"iDisplayLength" : 50,
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
//						"sScrollX" : "100%",
						"sScrollXInner" : "110%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "",
								"sPrevious" : "",
								"sNext" : "",
								"sLast" : ""
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
		"sAjaxSource" : "../../excavantionAnalysis/areaanalysis/gettailist",
		"fnServerData" : function(sSource, aoData, fnCallback) {
			$.ajax({
				"type" : "post",
				"contentType" : "application/x-www-form-urlencoded",
				"url" : sSource,
				"dataType" : "json",
				"data" : {
					"aoData" : JSON.stringify(aoData),
					timeSize : param.timeSize,
					city_code : param.city_code,
//					city : 113,
					queryDate : param.queryDate
				}, // 以json格式传递
				"success" : function(resp) {
					fnCallback(resp.pageDate);
					d=resp.allData;
				}
			});
		},
		columns : [ 
 // 去除小区名称列		           
//		{
//			data : "cell_name"
//		}, 
        { 
			data : "enodeb_id"
		},{
			data : "enodeb_name"
		},{
			data : "cell_id"
		},{
			data : "traffic_sum"
		}, {
			data : "frist_pack_time_delay"
		}, {
			data : "speed"
		}, {
			data : "user_num"
		} ]
	});
	console.log(datatable)
}
//获得sgw报表
function getSgwCharts() {
	// 查询
	sgwCharts.clear();
	sgwCharts.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/areaanalysis/getsgwcharts?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			timeSize : param.timeSize,
			city_code : param.city_code,
//			city : 113,
			queryDate : param.queryDate
		},
		success : function(data) {
			console.log(data)
			sgwCharts.setOption(data, true);
			sgwCharts.hideLoading();
		}
	});
}

//获得设备报表
function getTerminalCharts() {
	// 查询
	terminalCharts.clear();
	terminalCharts.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/areaanalysis/getterminalcharts?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			timeSize : param.timeSize,
			city_code : param.city_code,
//			city : 113,
			queryDate : param.queryDate
		},
		success : function(data) {
			console.log(data)
			terminalCharts.setOption(data, true);
			terminalCharts.hideLoading();
		}
	});
}

//获得应用报表
function getAppCharts() {
	// 查询
	appCharts.clear();
	appCharts.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/areaanalysis/getappcharts?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			timeSize : param.timeSize,
			city_code : param.city_code,
//			city : 113,
			queryDate : param.queryDate
		},
		success : function(data) {
			console.log(data)
			appCharts.setOption(data, true);
			appCharts.hideLoading();
		}
	});
}

	//获得业务组报表
function getBussinessGroupCharts() {
	// 查询
	bussinessGroupCharts.clear();
	bussinessGroupCharts.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/areaanalysis/getbusinessgroupcharts?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			timeSize : param.timeSize,
			city_code : param.city_code,
//			city : 113,
			queryDate : param.queryDate
		},
		success : function(data) {
			console.log(data)
			bussinessGroupCharts.setOption(data, true);
			bussinessGroupCharts.hideLoading();
		}
	});
}


function getAreaUserCharts() {
	// 查询
	areaUserCharts.clear();
	areaUserCharts.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/areaanalysis/getareauserlist?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			timeSize : param.timeSize,
			city_code : param.city_code,
//			city : 113,
			queryDate : param.queryDate
		},
		success : function(data) {
			console.log(data)
			areaUserCharts.setOption(data, true);
			areaUserCharts.hideLoading();
		}
	});
}

function getAreaFlowCharts() {
	// 查询
	areaFlowCharts.clear();
	areaFlowCharts.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/areaanalysis/getareaflowlist?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			timeSize : param.timeSize,
			city_code : param.city_code,
//			city : 113,
			queryDate : param.queryDate
		},
		success : function(data) {
			console.log(data)
			areaFlowCharts.setOption(data, true);
			areaFlowCharts.hideLoading();
		}
	});
}

function getUserFlowDistributeCharts() {
	// 查询
	userFlowDistributeCharts.clear();
	userFlowDistributeCharts.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../excavantionAnalysis/areaanalysis/getuserflowdistribute?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			timeSize : param.timeSize,
			city_code : param.city_code,
//			city : 113,
			queryDate : param.queryDate
		},
		success : function(data) {
			console.log(data)
			userFlowDistributeCharts.setOption(data, true);
			userFlowDistributeCharts.hideLoading();
		}
	});
}


function getAreaHeatMap(){
    if(isFirst==0){
        layer.load(2);
    }else{
        window.frames['map'].layerLoad();
    }

    $.ajax({

        type : "POST",
        url : "../../mapAnalysis/UserGruopAreaHeatMap",
        data : {
            timeType:param.timeSize,
            nowDate: param.queryDate,
            area_code:  param.city_code
        },
        dataType : "json",
        success : function(data) {
            MapData=data;

            changeType();
        //    changeType();
        }
    });


}

function changeType(){
    if(!MapData) {
        if(isFirst==0){
            layer.closeAll('loading');
        }else{
            window.frames['map'].closeLayer();
        }
        return;
    };
    var ops={
        type:"groupMap",
        data:"data",
        isRePlace:isReposition
    };

    switch($("input[name='type'][checked]").val()){
        case "userNum":
            ops.data="UserNum";

         break;
        case "flow":
            ops.data="Flow";
            break;
        default :
            ops.data="UserNum";
            break;
    }
    window.frames['map'].initMapData();
    if(isFirst==0){
        layer.closeAll('loading');
    }
    if(!MapData[ops.data]){
        window.frames['map'].noMapdata();

    }else{
        window.frames['map'].initData(MapData,ops);
        window.frames['map'].closeLayer();
    }
    if(isFirst==0){
        isFirst=1;
    }

}